/**
 * 
 */
package net.entelijan.cobean.bind.impl.remove;

import java.beans.PropertyChangeEvent;

import net.entelijan.cobean.core.IRemovable;
import net.entelijan.cobean.core.impl.INamedPropertyChangeListener;

class RecordingPropertyChangeListener implements INamedPropertyChangeListener, IRemovable {

    protected final StringBuffer buffer;
    
    protected String prefix = "1"; 
    
    private String name;

    public RecordingPropertyChangeListener(StringBuffer events, String name) {
        this.buffer = events;
        this.name = name;
    }

    public RecordingPropertyChangeListener(String prefix, StringBuffer events, String name) {
        this(events, name);
        this.prefix = prefix;
    }

    @Override
    public void propertyChange(PropertyChangeEvent evt) {
        buffer.append(prefix);
        buffer.append(evt.getOldValue());
        buffer.append(evt.getNewValue());
    }

    @Override
    public void remove() {
        buffer.append("R");
    }

    @Override
    public String getName() {
        return this.name;
    }

}